package com.yuezhu.fragment;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatSpinner;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.yuezhu.Model.DictionaryModel;
import com.yuezhu.Model.ProjectModel;
import com.yuezhu.R;
import com.yuezhu.activity.MyprojectActivity;
import com.yuezhu.been.DataChangedEvent;
import com.yuezhu.been.UserMsg;
import com.yuezhu.citylist.CityListActivity;
import com.yuezhu.constante.BusAction;
import com.yuezhu.control.TaskEngine;
import com.yuezhu.global.ApplicationContext;
import com.yuezhu.global.BaseFragment;
import com.yuezhu.util.LogUtils;
import com.yuezhu.util.LoginOut;
import com.yuezhu.util.MyToast;
import com.yuezhu.util.StringUtil;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class MyrojectFragment extends BaseFragment implements View.OnClickListener {
    ArrayList<String> arr1 = new ArrayList<>();
    @InjectView(R.id.spinner1)
    TextView spinner1;
    @InjectView(R.id.spinner2)
    AppCompatSpinner spinner2;
    @InjectView(R.id.spinner3)
    AppCompatSpinner spinner3;
    int screen_height = ApplicationContext.getInstance().getScreen_height();
    @InjectView(R.id.lin1)
    LinearLayout lin1;
    @InjectView(R.id.lin2)
    LinearLayout lin2;
    @InjectView(R.id.lin3)
    LinearLayout lin3;
    @InjectView(R.id.re1)
    LinearLayout re1;
    @InjectView(R.id.re2)
    LinearLayout re2;
    @InjectView(R.id.re3)
    LinearLayout re3;
    @InjectView(R.id.iv_bottome_left)
    ImageView ivBottomeLeft;
    @InjectView(R.id.iv_bottome_middle)
    ImageView ivBottomeMiddle;
    @InjectView(R.id.iv_bottome_right)
    ImageView ivBottomeRight;
    private static final int REQUEST_ID = 1;
    @InjectView(R.id.project_text1)
    TextView projectText1;
    @InjectView(R.id.project_text2)
    TextView projectText2;
    @InjectView(R.id.text1)
    TextView text1;
    @InjectView(R.id.text2)
    TextView text2;
    @InjectView(R.id.text3)
    TextView text3;
    @InjectView(R.id.mess_top_edit)
    TextView mess_top_edit;
    @InjectView(R.id.notice)
    View notice;

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = getActivity().getLayoutInflater().inflate(R.layout.activity_myroject, null);
        ButterKnife.inject(this, view);
        arr1 = DictionaryModel.getInstance().getTypeNameList();
        init();
        init2();

        setLiseners();
        ivBottomeLeft.setImageResource(R.drawable.message_left);
        ivBottomeRight.setImageResource(R.drawable.message_right);
        spinner1.setTag("1");
        if (UserMsg.getInstance().getLevel() == 0) {
            notice.setVisibility(View.VISIBLE);
        } else {
            notice.setVisibility(View.INVISIBLE);
        }
        notice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyToast.showDefaltToast("基本版仅支持地上高度150米以下的项目，高级版无此限制。升级说明请参见菜单中的关于页面");
            }
        });
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    public void show() {
        PartitionnformationFragment.CURRENT_PLAN = -1;
        if (MyprojectActivity.currentProjectModel == null) {
            mess_top_edit.setText("");
            text1.setText("");
            text2.setText("");
            text3.setText("");
        } else {
            mess_top_edit.setText(MyprojectActivity.currentProjectModel.bldgName);
            spinner1.setText(MyprojectActivity.getCityNameById(MyprojectActivity.currentProjectModel.cityId));
            spinner1.setTag(MyprojectActivity.currentProjectModel.cityId + "");
            spinner2.setSelection(arr1.indexOf(DictionaryModel.getInstance().getTypeByTypeId(MyprojectActivity.currentProjectModel.bldgType).typeName));
            spinner3.setSelection(arr.indexOf(DictionaryModel.getInstance().getGradeByGradeId(MyprojectActivity.currentProjectModel.bldgGrade).gradeName));
            text1.setText(MyprojectActivity.currentProjectModel.bldgHeight + "");
            text2.setText(MyprojectActivity.currentProjectModel.bldgFloors + "");
            text3.setText(MyprojectActivity.currentProjectModel.floorValue + "");
        }
    }

    private void init() {
        re1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), CityListActivity.class);
                startActivityForResult(intent, REQUEST_ID);
            }
        });
    }

    private void init2() {
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, arr1) {
            @Override
            public View getDropDownView(int position, View convertView,
                                        ViewGroup parent) {
                View view = LayoutInflater.from(getContext()).inflate(R.layout.item_spinner, null);
                TextView label = (TextView) view.findViewById(R.id.spinner_item_label);
                label.setText(arr1.get(position));
                return view;
            }
        };
//        arrayAdapter.setDropDownViewResource(R.layout.item_spinner);
        //设置显示的数据

        spinner2.setAdapter(arrayAdapter);

        //注册事件
        spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                                       int position, long id) {
                init3(position);
                spinner2.setDropDownVerticalOffset(spinner2.getHeight());
                switch (position) {
                    case 1:
                        projectText1.setText("标准层客房数");
                        projectText2.setText("客房/层");
                        break;
                    default:
                        projectText1.setText("标准层建筑面积");
                        projectText2.setText("平方米/层");
                        break;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }

        });
    }

    /* 办公：3 超甲级，2 甲级
     酒店：3 城市型，2 度假型，1 经济型
     住宅：3 高档，2 中档，1 经济型*/
    ArrayList<String> arr = new ArrayList<>();

    private void init3(int position) {
        arr = DictionaryModel.getInstance().getGradeNameListByTypeName(arr1.get(position));
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, arr) {
            @Override
            public View getDropDownView(int position, View convertView,
                                        ViewGroup parent) {
                View view = LayoutInflater.from(getContext()).inflate(R.layout.item_spinner, null);
                TextView label = (TextView) view.findViewById(R.id.spinner_item_label);
                label.setText(arr.get(position));
                return view;
            }
        };
        //设置显示的数据
        spinner3.setAdapter(arrayAdapter);
        //注册事件
        spinner3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                                       int position, long id) {
                spinner3.setDropDownVerticalOffset(spinner3.getHeight());
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }

        });
    }

    private void setpa() {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lin1.getLayoutParams();
        params.width = screen_height / 3;
        lin1.setLayoutParams(params);
        lin2.setLayoutParams(params);
        lin3.setLayoutParams(params);
        LinearLayout.LayoutParams params1 = (LinearLayout.LayoutParams) re1.getLayoutParams();
        params1.width = screen_height / 3;
        re1.setLayoutParams(params1);
        re2.setLayoutParams(params1);
        re3.setLayoutParams(params1);
    }

    @Override
    public void initview(View view) {

    }

    @Override
    public void setLiseners() {
        ivBottomeLeft.setOnClickListener(this);
        ivBottomeRight.setOnClickListener(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_bottome_left:
                if (MyprojectActivity.currentProjectModel == null) {
                    EventBus.getDefault().post(new BusAction.mymessBack());
                } else {
                    if (TextUtils.isEmpty(spinner1.getText()) || TextUtils.isEmpty(spinner2.getSelectedItem().toString()) || TextUtils.isEmpty(spinner3.getSelectedItem().toString()) ||
                            TextUtils.isEmpty(text1.getText()) || TextUtils.isEmpty(text2.getText()) || TextUtils.isEmpty(text3.getText()) || TextUtils.isEmpty(mess_top_edit.getText())) {
                        MyToast.showDefaltToast("参数不能为空");
                        return;
                    }
                    try {
                        int f = Integer.parseInt(text2.getText().toString());
                        if (f < 1) {
                            MyToast.showDefaltToast("地上楼层数必须大于0");
                            return;
                        }
                    } catch (Exception e) {
                        MyToast.showDefaltToast("地上楼层数输入有误，请重新输入！");
                        return;
                    }
                    String bldgName = mess_top_edit.getText().toString();
                    String city = spinner1.getText().toString();
                    String bldgType = spinner2.getSelectedItem().toString();
                    String bldgGrade = spinner3.getSelectedItem().toString();
                    String bldgHeight = text1.getText().toString();
                    String bldgFloors = text2.getText().toString();
                    String floorValue = text3.getText().toString();
                    final HashMap<String, String> map = new HashMap<>();
                    map.put("bldgName", bldgName);
                    map.put("bldgType", DictionaryModel.getInstance().getTypeIDByTypeNmae(bldgType) + "");
                    map.put("bldgGrade", DictionaryModel.getInstance().getGradeIdByGradeName(bldgGrade) + "");
                    map.put("bldgHeight", bldgHeight);
                    map.put("bldgFloors", bldgFloors);
                    map.put("floorValue", floorValue);
                    map.put("floorHeight", "0");
                    map.put("cityId", spinner1.getTag().toString());
                    try {
                        int floor = Integer.parseInt(bldgHeight);
                        if (UserMsg.getInstance().getLevel() == 0 && floor > 150) {
                            MyToast.showDefaltToast("基本版仅支持地上高度150米以下的项目，高级版无此限制。升级说明请参见菜单中的关于页面");
                            return;
                        }
                    } catch (Exception e) {
                        MyToast.showDefaltToast("高度输入错误");
                        return;
                    }
                    if (map.get("bldgName").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgName)
                            && map.get("bldgType").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgType + "")
                            && map.get("bldgGrade").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgGrade + "")
                            && map.get("bldgHeight").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgHeight + "")
                            && map.get("bldgFloors").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgFloors + "")
                            && map.get("floorValue").equalsIgnoreCase(MyprojectActivity.currentProjectModel.floorValue + "")
                            && map.get("cityId").equalsIgnoreCase(MyprojectActivity.currentProjectModel.cityId + "")) {
                        EventBus.getDefault().post(new BusAction.mymessBack());
                    } else {
                        if (!map.get("bldgFloors").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgFloors + "")) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());  //先得到构造器
                            builder.setTitle("提示"); //设置标题
                            builder.setMessage("更改楼层数将会删除之前的方案！\n是否继续？"); //设置内容
                            builder.setCancelable(false);
                            builder.setPositiveButton("继续", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    map.put("bldgId", MyprojectActivity.currentProjectModel.bldgId);
                                    map.put("userId", UserMsg.getInstance().getUserID());
                                    TaskEngine.getInstance().startUpdateProjectTask(queue, map, new Response.Listener<JSONObject>() {
                                        @Override
                                        public void onResponse(JSONObject json) {
                                            try {
                                                String respCode = json.getString("respCode");
                                                if (!StringUtil.equal(respCode, "OK")) {
                                                    try {
                                                        if (json.getInt("respNo") == 999) {
                                                            LoginOut.LoginOut(getActivity());
                                                        }
                                                    } catch (Exception e) {
                                                        MyToast.showDefaltToast("项目更新失败");
                                                    }
                                                } else {
                                                    MyprojectActivity.currentProjectModel.bldgName = map.get("bldgName");
                                                    MyprojectActivity.currentProjectModel.bldgType = Integer.parseInt(map.get("bldgType"));
                                                    MyprojectActivity.currentProjectModel.bldgGrade = Integer.parseInt(map.get("bldgGrade"));
                                                    MyprojectActivity.currentProjectModel.bldgHeight = Integer.parseInt(map.get("bldgHeight"));
                                                    MyprojectActivity.currentProjectModel.bldgFloors = Integer.parseInt(map.get("bldgFloors"));
                                                    MyprojectActivity.currentProjectModel.floorValue = Integer.parseInt(map.get("floorValue"));
                                                    MyprojectActivity.currentProjectModel.cityId = Integer.parseInt(map.get("cityId"));
                                                    MyToast.showDefaltToast(json.getString("respDesc"));
                                                    EventBus.getDefault().post(new BusAction.mymessBack());
                                                }
                                            } catch (Exception e) {
                                                MyToast.showDefaltToast("项目更新失败");
                                            }
                                        }
                                    }, new Response.ErrorListener() {
                                        @Override
                                        public void onErrorResponse(VolleyError volleyError) {
                                            MyToast.showDefaltToast("项目更新失败");
                                        }
                                    });
                                }
                            });
                            builder.setNegativeButton("取消", null);
                            builder.create().show();
                        } else {
                            map.put("bldgId", MyprojectActivity.currentProjectModel.bldgId);
                            map.put("userId", UserMsg.getInstance().getUserID());
                            TaskEngine.getInstance().startUpdateProjectTask(queue, map, new Response.Listener<JSONObject>() {
                                @Override
                                public void onResponse(JSONObject json) {
                                    try {
                                        String respCode = json.getString("respCode");
                                        if (!StringUtil.equal(respCode, "OK")) {
                                            try {
                                                if (json.getInt("respNo") == 999) {
                                                    LoginOut.LoginOut(getActivity());
                                                }
                                            } catch (Exception e) {
                                                MyToast.showDefaltToast("项目更新失败");
                                            }
                                        } else {
                                            MyprojectActivity.currentProjectModel.bldgName = map.get("bldgName");
                                            MyprojectActivity.currentProjectModel.bldgType = Integer.parseInt(map.get("bldgType"));
                                            MyprojectActivity.currentProjectModel.bldgGrade = Integer.parseInt(map.get("bldgGrade"));
                                            MyprojectActivity.currentProjectModel.bldgHeight = Integer.parseInt(map.get("bldgHeight"));
                                            MyprojectActivity.currentProjectModel.bldgFloors = Integer.parseInt(map.get("bldgFloors"));
                                            MyprojectActivity.currentProjectModel.floorValue = Integer.parseInt(map.get("floorValue"));
                                            MyprojectActivity.currentProjectModel.cityId = Integer.parseInt(map.get("cityId"));
                                            MyToast.showDefaltToast(json.getString("respDesc"));
                                            EventBus.getDefault().post(new BusAction.mymessBack());
                                        }
                                    } catch (Exception e) {
                                        MyToast.showDefaltToast("项目更新失败");
                                    }
                                }
                            }, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError volleyError) {
                                    MyToast.showDefaltToast("项目更新失败");
                                }
                            });
                        }
                    }
                }
//                EventBus.getDefault().post(new BusAction.mymessBack());
//                BusProvider.getInstance().post(new DataChangedEvent(BusAction.MYMESS_BACK));
                break;
            case R.id.iv_bottome_right:
                if (TextUtils.isEmpty(spinner1.getText()) || TextUtils.isEmpty(spinner2.getSelectedItem().toString()) || TextUtils.isEmpty(spinner3.getSelectedItem().toString()) ||
                        TextUtils.isEmpty(text1.getText()) || TextUtils.isEmpty(text2.getText()) || TextUtils.isEmpty(text3.getText()) || TextUtils.isEmpty(mess_top_edit.getText())) {
                    MyToast.showDefaltToast("参数不能为空");
                    return;
                }
                try {
                    int f = Integer.parseInt(text2.getText().toString());
                    if (f < 1) {
                        MyToast.showDefaltToast("地上楼层数必须大于0");
                        return;
                    }
                } catch (Exception e) {
                    MyToast.showDefaltToast("地上楼层数输入有误，请重新输入！");
                    return;
                }
                String bldgName = mess_top_edit.getText().toString();
                String city = spinner1.getText().toString();
                String bldgType = spinner2.getSelectedItem().toString();
                String bldgGrade = spinner3.getSelectedItem().toString();
                String bldgHeight = text1.getText().toString();
                String bldgFloors = text2.getText().toString();
                String floorValue = text3.getText().toString();
                final HashMap<String, String> map = new HashMap<>();
                map.put("bldgName", bldgName);
                map.put("bldgType", DictionaryModel.getInstance().getTypeIDByTypeNmae(bldgType) + "");
                map.put("bldgGrade", DictionaryModel.getInstance().getGradeIdByGradeName(bldgGrade) + "");
                map.put("bldgHeight", bldgHeight);
                map.put("bldgFloors", bldgFloors);
                map.put("floorValue", floorValue);
                map.put("floorHeight", "0");
                map.put("cityId", spinner1.getTag().toString());
                try {
                    int floor = Integer.parseInt(bldgHeight);
                    if (UserMsg.getInstance().getLevel() == 0 && floor > 150) {
                        MyToast.showDefaltToast("基本版仅支持地上高度150米以下的项目，高级版无此限制。升级说明请参见菜单中的关于页面");
                        return;
                    }
                } catch (Exception e) {
                    MyToast.showDefaltToast("高度输入错误");
                    return;
                }
                if (MyprojectActivity.currentProjectModel == null) {
                    TaskEngine.getInstance().startAddProjectTask(queue, map, new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject json) {
                            try {
                                String respCode = json.getString("respCode");
                                if (!StringUtil.equal(respCode, "OK")) {
                                    try {
                                        if (json.getInt("respNo") == 999) {
                                            LoginOut.LoginOut(getActivity());
                                        }
                                    } catch (Exception e) {
                                        MyToast.showDefaltToast("项目添加失败");
                                    }
                                } else {
                                    HashMap<String, String> map = new HashMap<>();
                                    map.put("bldgId", json.getString("bldgId"));
                                    TaskEngine.getInstance().startGetProjectTask(queue, map, new Response.Listener<JSONObject>() {
                                        @Override
                                        public void onResponse(JSONObject json) {
                                            try {
                                                String respCode = json.getString("respCode");
                                                if (!StringUtil.equal(respCode, "OK")) {
                                                    try {
                                                        if (json.getInt("respNo") == 999) {
                                                            LoginOut.LoginOut(getActivity());
                                                        }
                                                    } catch (Exception e) {
                                                        MyToast.showDefaltToast("项目添加失败");
                                                    }
                                                } else {
                                                    MyToast.showDefaltToast(json.getString("respDesc"));
                                                    MyprojectActivity.currentProjectModel = new Gson().fromJson(json.getString("bldgInfo").toString(), ProjectModel.class);
                                                    EventBus.getDefault().post(new BusAction.mymessPart1());
                                                }
                                            } catch (Exception e1) {

                                            }
                                        }
                                    }, new Response.ErrorListener() {
                                        @Override
                                        public void onErrorResponse(VolleyError volleyError) {

                                        }
                                    });
                                }
                            } catch (Exception e) {
                                MyToast.showDefaltToast("项目添加失败");
                            }
                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError volleyError) {
                            MyToast.showDefaltToast("项目添加失败");
                        }
                    });
                } else {
                    if (map.get("bldgName").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgName)
                            && map.get("bldgType").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgType + "")
                            && map.get("bldgGrade").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgGrade + "")
                            && map.get("bldgHeight").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgHeight + "")
                            && map.get("bldgFloors").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgFloors + "")
                            && map.get("floorValue").equalsIgnoreCase(MyprojectActivity.currentProjectModel.floorValue + "")
                            && map.get("cityId").equalsIgnoreCase(MyprojectActivity.currentProjectModel.cityId + "")) {
                        try {
                            EventBus.getDefault().post(new BusAction.mymessPart1());
//                            BusProvider.getInstance().post(new DataChangedEvent(BusAction.MYMESS_PART1));
                        } catch (Exception eq) {

                        }
                    } else {
                        if (!map.get("bldgFloors").equalsIgnoreCase(MyprojectActivity.currentProjectModel.bldgFloors + "")) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());  //先得到构造器
                            builder.setTitle("提示"); //设置标题
                            builder.setMessage("更改楼层数将会删除之前的方案！\n是否继续？"); //设置内容
                            builder.setCancelable(false);
                            builder.setPositiveButton("继续", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    map.put("bldgId", MyprojectActivity.currentProjectModel.bldgId);
                                    map.put("userId", UserMsg.getInstance().getUserID());
                                    TaskEngine.getInstance().startUpdateProjectTask(queue, map, new Response.Listener<JSONObject>() {
                                        @Override
                                        public void onResponse(JSONObject json) {
                                            try {
                                                String respCode = json.getString("respCode");
                                                if (!StringUtil.equal(respCode, "OK")) {
                                                    try {
                                                        if (json.getInt("respNo") == 999) {
                                                            LoginOut.LoginOut(getActivity());
                                                        }
                                                    } catch (Exception e) {
                                                        MyToast.showDefaltToast("项目更新失败");
                                                    }
                                                } else {
                                                    MyprojectActivity.currentProjectModel.bldgName = map.get("bldgName");
                                                    MyprojectActivity.currentProjectModel.bldgType = Integer.parseInt(map.get("bldgType"));
                                                    MyprojectActivity.currentProjectModel.bldgGrade = Integer.parseInt(map.get("bldgGrade"));
                                                    MyprojectActivity.currentProjectModel.bldgHeight = Integer.parseInt(map.get("bldgHeight"));
                                                    MyprojectActivity.currentProjectModel.bldgFloors = Integer.parseInt(map.get("bldgFloors"));
                                                    MyprojectActivity.currentProjectModel.floorValue = Integer.parseInt(map.get("floorValue"));
                                                    MyprojectActivity.currentProjectModel.cityId = Integer.parseInt(map.get("cityId"));
                                                    MyToast.showDefaltToast(json.getString("respDesc"));
                                                    try {
                                                        EventBus.getDefault().post(new BusAction.mymessPart1());
//                                            BusProvider.getInstance().post(new DataChangedEvent(BusAction.MYMESS_PART1));
                                                    } catch (Exception eq) {

                                                    }
                                                }
                                            } catch (Exception e) {
                                                MyToast.showDefaltToast("项目更新失败");
                                            }
                                        }
                                    }, new Response.ErrorListener() {
                                        @Override
                                        public void onErrorResponse(VolleyError volleyError) {
                                            MyToast.showDefaltToast("项目更新失败");
                                        }
                                    });
                                }
                            });
                            builder.setNegativeButton("取消", null);
                            builder.create().show();
                        } else {
                            map.put("bldgId", MyprojectActivity.currentProjectModel.bldgId);
                            map.put("userId", UserMsg.getInstance().getUserID());
                            TaskEngine.getInstance().startUpdateProjectTask(queue, map, new Response.Listener<JSONObject>() {
                                @Override
                                public void onResponse(JSONObject json) {
                                    try {
                                        String respCode = json.getString("respCode");
                                        if (!StringUtil.equal(respCode, "OK")) {
                                            try {
                                                if (json.getInt("respNo") == 999) {
                                                    LoginOut.LoginOut(getActivity());
                                                }
                                            } catch (Exception e) {
                                                MyToast.showDefaltToast("项目更新失败");
                                            }
                                        } else {
                                            MyprojectActivity.currentProjectModel.bldgName = map.get("bldgName");
                                            MyprojectActivity.currentProjectModel.bldgType = Integer.parseInt(map.get("bldgType"));
                                            MyprojectActivity.currentProjectModel.bldgGrade = Integer.parseInt(map.get("bldgGrade"));
                                            MyprojectActivity.currentProjectModel.bldgHeight = Integer.parseInt(map.get("bldgHeight"));
                                            MyprojectActivity.currentProjectModel.bldgFloors = Integer.parseInt(map.get("bldgFloors"));
                                            MyprojectActivity.currentProjectModel.floorValue = Integer.parseInt(map.get("floorValue"));
                                            MyprojectActivity.currentProjectModel.cityId = Integer.parseInt(map.get("cityId"));
                                            MyToast.showDefaltToast(json.getString("respDesc"));
                                            try {
                                                EventBus.getDefault().post(new BusAction.mymessPart1());
//                                            BusProvider.getInstance().post(new DataChangedEvent(BusAction.MYMESS_PART1));
                                            } catch (Exception eq) {

                                            }
                                        }
                                    } catch (Exception e) {
                                        MyToast.showDefaltToast("项目更新失败");
                                    }
                                }
                            }, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError volleyError) {
                                    MyToast.showDefaltToast("项目更新失败");
                                }
                            });
                        }
                    }
                }
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
            case REQUEST_ID:
                String city = data.getStringExtra("city");
                spinner1.setText(city);
                spinner1.setTag(data.getIntExtra("id", 1) + "");
                break;
        }
    }
}
